<?php
//代码查找
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'search';
if($_RQ['op']=='search'){
	$params=array(
		'fields'=>array('id','title')
	);
	$return['plugins']=$this->get_list('plugin',$params);
	if($_RQ['search'] && $_RQ['plugin']){
		$search=trim($_RQ['search']);
		$search=htmlspecialchars_decode($search,ENT_QUOTES);
		$plugin_id=intval($_RQ['plugin']);
		$plugin=$this->getcolumn('plugin',array('id'=>$plugin_id),'name');
		$dir=ROOT_D.'/addons/'.$plugin;
		$type=array();
		if($_RQ['type']){
			$temp=trim($_RQ['type'],';');
			if($temp){
				$temp=explode(';',$temp);
				foreach($temp as $row){
					$type[]=$return['types'][$row];
				}
			}
		}
		$files=cfc('files')->file_tree($dir,$ignore,$type);
		$result=array();
		foreach($files as $file){
			if(is_file($dir.$file)){
				$data=file_get_contents($dir.$file);
				if(strpos($data,$search)){
					$result[]=$file;
				}
			}
		}
		$return['list']=$result;
		$return['search']=$search;
		$return['plugin']=$plugin_id;
	}else{
		$return['list']=array();
	}
	exi($return);
}